﻿using System;
using WinHBM.Utils;
namespace WinHBM.Core.Bluetooth
{

    public enum FlowerType
    {
        Red,Gold,CheckIn,CheckOut
    }
    public class RedFlower
    {
        public FlowerType type;
        public int year;
        public int month;
        public int day;
        public int hour;
        public int minute;
        public int second;
        public int teacherId;
        public int studentId;
         
        public static RedFlower FromBytes(byte[] data)
        {
            RedFlower obj = new RedFlower();
            obj.year = data[5] * 256 + data[6];
            obj.month = data[7];
            obj.day = data[8];
            obj.hour = data[9];
            obj.minute = data[10];
            obj.second = data[11];
            byte[] stuidtemp = { data[12], data[13], data[14], data[15] };
            obj.studentId = UtilByte.ToInt32(stuidtemp);
            byte[] teacheridtemp = { data[16], data[17], data[18], data[19] };
            obj.teacherId = UtilByte.ToInt32(teacheridtemp);
            switch(data[20])
            {
                case 0x42:
                    obj.type = FlowerType.Red;
                    break;
                    
                case 0x41:
                    obj.type = FlowerType.Gold;
                    break;

                case 0x49:
                    obj.type = FlowerType.CheckOut;
                    break;

                case 0x4E:
                    obj.type = FlowerType.CheckIn;
                    break;
            }
            return obj;
        }

        public override string ToString()
        {
            return "{type:" + type + ",year:" + year + ",month:" + month + ",day:" + day + ",hour:" + hour + ",minute:" + minute + ",second:" + second + ",teacherId:" + teacherId + ",studentId:" + studentId + "}";
        }

    }
}
